package com.shopping_back.mapper;

import com.shopping_back.pojo.entity.Sku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shopping_back.pojo.vo.SkuVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商品SKU表 Mapper 接口
 * </p>
 *
 * @author Jack
 * @since 2025-07-12
 */
@Mapper
public interface SkuMapper extends BaseMapper<Sku> {
    // 根据SPU ID查询对应的SKU列表（查询所有SKU，无论状态，由前端决定是否展示下架SKU）
    @Select("SELECT * FROM sku WHERE spu_id = #{spuId}")
    List<Sku> selectBySpuId(Long spuId);

    List<SkuVO> selectSkuWithSpuTitle();

    List<SkuVO> selectSkuByMerchantId(Long merchantId);

    @Select("SELECT * FROM sku WHERE id = #{skuId} LIMIT 1")
    Sku selectSkuById(Long skuId);

    @org.apache.ibatis.annotations.Update("UPDATE sku SET stock = #{stock} WHERE id = #{skuId}")
    int updateSkuStock(@org.apache.ibatis.annotations.Param("skuId") Long skuId, @org.apache.ibatis.annotations.Param("stock") Integer stock);
}
